#include "../tools.h"

// The rand7() API is already defined for you.
// int rand7();
// @return a random integer in the range 1 to 7
int rand7();

class Solution {
public:
    int rand10() {
        while(true){
            int a = rand7();
            int b = rand7();
            int res = (a - 1) * 7 + b; // rand_49 [1, 49]
            if(res <= 40) return res % 10 + 1;

            a = res - 40; // rand_9
            b = rand7();
            res = (a - 1) * 7 + b; // rand_63
            if(res <= 60) return res % 10 + 1;

            a = res - 60; // rand_3
            b = rand7();
            res = (a - 1) * 7 + b; // rand_21
            if(res <= 20) return res % 10 + 1;
        }
    }
};

int main(int argc, char const *argv[])
{
    
    return 0;
}
